package pt.uc.dei.mse.eai.screenScrapping;

import java.io.IOException;
import java.util.HashMap;

import pt.uc.dei.mse.eai.model.dataModel.Cinema;

/**
 * A CineSiteScrapper is an object capable of browsing a cinemas web site and returing 
 * its data as a Cinema object. In the first step it should be used to grab the list of 
 * Cinemas from the home page.
 * 
 * @author XPTS929
 *
 */
public class CineSiteScrapper {

	private String currentHomePageURL = "";

	/**
	 * The constructor receives the site home page address
	 * @param homePageURL
	 */
	public CineSiteScrapper(String homePageURL) {
		currentHomePageURL = homePageURL;
	}

	/**
	 * @return a hashtable (Cinema name -> Cinema link) grabbed from the home page
	 * @throws IOException
	 */
	public HashMap<String, String> getCinemasList() throws IOException {
		String homePageContents = HttpClientUtils.getPage(currentHomePageURL);
		return PageParser.getCinemasLinksFromHomePage(homePageContents);
	}

	/**
	 * 
	 * @param cinemaPageURL
	 * @return a Cinema object grabbed from a Cinema page
	 * @throws IOException
	 */
	public Cinema getCinemaInfoFromPage(String cinemaPageURL)
			throws IOException {
		String cinePageContents = HttpClientUtils.getPage(cinemaPageURL);
		return PageParser.getCinemaInfoFromCinemaPage(cinePageContents,
				currentHomePageURL);
	}

	/**
	 * Sets the site's home web page
	 * @param currentHomePageURL
	 */
	public void setCurrentHomePageURL(String currentHomePageURL) {
		this.currentHomePageURL = currentHomePageURL;
	}

	/**
	 *	Return the site's home web page 
	 */
	public String getCurrentHomePageURL() {
		return this.currentHomePageURL;
	}

}
